Receives data from the remote host.
Syntax
Visual Basic (Declaration) | |
---|
Public Overloads Function Read( _
ByVal buffer() As Byte _
) As Data |
Visual Basic (Usage) | Copy Code |
---|
Dim instance As TcpBase
Dim buffer() As Byte
Dim value As Data
value = instance.Read(buffer) |
Parameters
- buffer
- The byte array used to store the received data.
Return Value
A
Data object encapsulating the received data.
Example
This example demonstrates execution of a looping Read on a worker thread, and marshaling the data back to the UI. This specific example uses the Telnet component, but the code is the same for any component that derives from TcpBase.
C# | Copy Code |
---|
//Receive data on a separate thread
telnet1.Start(receiveData, null);
private void receiveData(Telnet telnet, object notUsed)
{
//Receive data when it is sent by the remote host
byte[] buffer = new byte[1024];
while (telnet.State != Dart.Common.ConnectionState.Closed)
telnet.Marshal(telnet.Read(buffer, 0, 1024), null);
}
private void telnet1_Data(object sender, DataEventArgs e)
{
//Whenever data is received, display it
textDisplay.Text + e.Data.ToString();
} |
Visual Basic | Copy Code |
---|
'Receive data on a separate thread
telnet.Start(AddressOf receiveData, Nothing)
Private Sub receiveData(ByVal telnet As Telnet, ByVal notUsed As Object)
'Receive data when it is sent by the remote host
Dim buffer() As Byte = New Byte(1023){}
Do While telnet.State <> ConnectionState.Closed
telnet.Marshal(telnet.Read(buffer, 0, 1024), Nothing)
Loop
End Sub
Private Sub telnet1_Data(ByVal sender As Object, ByVal e As DataEventArgs) Handles telnet1.Read
'Whenever data is received, display it
textDisplay.Text = e.Data.ToString()
End Sub |
Remarks
Requirements
Target Platforms: Microsoft .NET Framework 2.0
See Also